Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

DDirect3D.hpp

Go to the documentation of this file.
00001 ///////////////////////////////////////////////////////////////////////////////
00002 /// @file DDirect3D.hpp
00003 ///
00004 /// @brief class for Direct3D8 driver
00005 ///
00006 /// @author Lightning
00007 ///
00008 /// This file is the intellectual property of Novus Delta, LLC.. Usage of the
00009 /// contents of this file is subject to the Destiny3D Member License which
00010 /// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
00011 ///
00012 /// This file is distributed "AS IS" without warranty of any kind.  Novus
00013 /// Delta, LLC. does not guarantee the fitness of the contents of this file
00014 /// for any particular purpose.
00015 ///
00016 /// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
00017 ///
00018 /// <hr>
00019 ///                                 Change History
00020 /// <hr>
00021 ///
00022 /// @date Aug 2001
00023 /// @author Lightning
00024 /// @remarks Creation
00025 ///
00026 /// @date May 2002
00027 /// @author Assassin
00028 /// @remarks Sub-VBuffer modifications
00029 ///
00030 ///////////////////////////////////////////////////////////////////////////////
00031 
00032 #ifndef DDIRECT3D_HPP
00033 #define DDIRECT3D_HPP
00034 
00035 #pragma comment(lib, "d3dx8")
00036 
00037 #define DEDRIVER_DLL_EXPORTS
00038 #define USING_DESTINY3D
00039 
00040 //needed global headers
00041 #include <d3d8.h>
00042 #include <d3dx8.h>
00043 #include "Destiny3D.hpp"
00044 #include "deGlobalTypes.hpp"
00045 
00046 //include the needed driver headers
00047 #include "deDriver_priv.hpp"
00048 #include "deList.hpp"
00049 #include "deHash.hpp"
00050 
00051 static const long deD3D8_MAX_LIGHTS = 8;
00052 
00053 //the Direct3D class
00054 class deDirect3D8 : public deDriver
00055 {
00056 public:
00057     //constructor and destructor
00058     deDirect3D8(long ID);
00059     ~deDirect3D8();
00060     long Release();
00061     deBoolean Init(HWND WindowHandle);
00062 
00063     //adapter and mode counts for adapters
00064     const deDriverCaps* GetCaps(long Adapter) const;
00065     long GetAdapterCount() const;
00066     long GetModeCount(long Adapter) const;
00067     deBoolean WindowedAllowed(long Adapter) const;
00068 
00069     //display settings
00070     deBoolean SetDisplay(deDisplay *Display);
00071     deBoolean Reset(deDisplay *Display = NULL);
00072     deBoolean GetCurrentDisplay(long Adapter, deDisplay * Display) const;
00073     deBoolean GetDisplayMode(long Adapter, long Mode, deDisplay *Display) const;
00074     deBoolean ValidFormat(long Adapter, Resource ResourceType, BPP BPPType, ZPP ZPPType, BPP FrontBuffer, long ExtraFlag) const;
00075     
00076     //vertex buffer functions
00077     deBoolean AddVertexBuffer(IdeVertexBuffer *Vertex);
00078     deBoolean RemoveVertexBuffer(IdeVertexBuffer *Vertex);
00079     deBoolean UpdateVertexBuffer(IdeVertexBuffer *Vertex);
00080 
00081     // Shader functions
00082     deBoolean AddShader(IdeShader * Shader);
00083     deBoolean SetShader(IdeShader * Shader);
00084     deBoolean RemoveShader(IdeShader * Shader);
00085 
00086     //frame functions
00087     deBoolean BeginFrame();
00088     deBoolean EndFrame();
00089     deBoolean ClearFrame(deARGB Color, deBoolean ClearTarget, deBoolean ClearZBuffer, deBoolean ClearStencil);
00090     deBoolean Render(IdeVertexBuffer *Vertex, long IndexOffset, IdeVertexBuffer *IndexOverride);
00091 
00092     //viewport/FOV functions
00093     deBoolean SetViewport(long X, long Y, long Width, long Height, float MinZ, float MaxZ);
00094     deBoolean SetDepthRange(deFloat MinZ, deFloat MaxZ);
00095     deBoolean SetFOVClipping(float FOVY, float Aspect, float ClipNear, float ClipFar);
00096     deBoolean SetOrthoClipping(float Width, float Height, float ClipNear, float ClipFar, deBoolean Invert);
00097     deBoolean SetFOVClippingSubRect(deFloat FOVY, deFloat Aspect, deFloat ClipNear, deFloat ClipFar, deRect SubRect);
00098     deBoolean SetFOVClippingSubRectFloat(deFloat FOVY, deFloat Aspect, deFloat ClipNear, deFloat ClipFar, deFloatRect SubRect);
00099     deBoolean SetOrthoClippingSubRect(deFloat Width, deFloat Height, deFloat ClipNear, deFloat ClipFar, deBoolean Invert, deRect SubRect);
00100     deBoolean SetOrthoClippingSubRectFloat(deFloat Width, deFloat Height, deFloat ClipNear, deFloat ClipFar, deBoolean Invert, deFloatRect SubRect);
00101     
00102     //camera translation functions
00103     deBoolean SetCameraTransform(deTransformInfo *M);
00104     deBoolean SetCameraTransform(deVertex *Eye, deVertex *At, deVertex *Up);
00105     deBoolean SetCameraTranslation(deVertex *Translation);
00106     deBoolean SetCameraRotation(deVertex *Rotation);
00107     deBoolean ResetCameraIdentity();
00108 
00109     //world translation functions
00110     deBoolean SetWorldTransform(deTransformInfo * Mat);
00111     deBoolean SetWorldTransform(deVertex *Eye, deVertex *At, deVertex *Up);
00112     deBoolean SetWorldTranslation(deVertex *Translation);
00113     deBoolean SetWorldRotation(deVertex *Rotation);
00114     deBoolean ResetWorldIdentity();
00115 
00116     deBoolean SetTextureTransform(long StageNum, deTransformInfo * Mat);
00117 
00118     //texture functions
00119     deBoolean AddBitmap(IdeBitmap *Bitmap);
00120     deBoolean AddBitmapProxy(IdeBitmapProxy *BitmapProxy);
00121     deBoolean RemoveBitmap(IdeBitmap *Bitmap);
00122 
00123     //render-to-texture functions
00124     deBoolean RenderTo(IdeBitmap *Bitmap, long CubeMapFace);
00125     deBoolean ScreenShot(IdeBitmap * &pBitmap, deBoolean GrabWindow);
00126     deBoolean GetVideoTexture(IdeBitmap* pBitmap, long CubeMapFace);
00127     
00128     //render states
00129     unsigned long GetRenderState(RenderState State);
00130     deBoolean SetRenderState(const IdeRenderState *State);
00131     deBoolean SetRenderState(RenderState State, unsigned long Value);
00132     deBoolean EnableLight(long LightID, deBoolean Enable);
00133     deBoolean DisableAllLights();
00134     
00135     //driver info
00136     deDriverInfo* GetInfo() const;
00137     IdeDriver::Types GetType() const;
00138 
00139     void InvalidateRenderStates(deBoolean Valid);
00140 private:
00141     struct VertexShaderEntry
00142     {
00143         long                        ID;             //ID to verify the structure
00144         unsigned long               VertexShader;   //the vertex shader ID
00145         unsigned long *             ShaderInfo;     //the shader command info
00146         long                        BufferFlags;    //record of which buffers are in it
00147         // everything below has to go
00148     };
00149     struct VertexBufferEntry
00150     {
00151         long                        ID;             //ID to verify the structure
00152         long                        EntrySize[IdeVertexBuffer::BUFFER_COUNT-1];     //size of each entry
00153         LPDIRECT3DVERTEXBUFFER8     Buffers[IdeVertexBuffer::BUFFER_COUNT-1];       //the actual buffers to render
00154         LPDIRECT3DINDEXBUFFER8      IndexBuffer;    //the index buffer
00155         D3DPRIMITIVETYPE            RenderType;     //type of rendering to do
00156         long                        PointCount;     //number of points
00157         long                        TriCount;       //number of tris
00158         long                        IndexCount;     //number of index entries
00159         long                        PointStart;
00160         long                        IndexStart;
00161         long                        FrameUsed;
00162         deBoolean                   SubBuffer;
00163     };
00164 
00165     struct TextureEntry
00166     {
00167         long                    ID;             //ID to verify the struct
00168         long                    NumFaces;       //if in a cubemap, the face ID
00169         long                    FrameUsed;
00170         LPDIRECT3DBASETEXTURE8  Texture;        //pointer to the texture
00171         LPDIRECT3DSURFACE8      DepthStencil;   //pointer (possibly null) to depth-stencil surface if the texture is render-able
00172     };
00173 
00174     // static variables
00175     static long             s_AdapterCount;         //number of adapters
00176     static int *            s_ModeCount;            //total number of modes
00177     static deBoolean *      s_WindowPossible;       //if each adapter can do windowed
00178     static HINSTANCE        s_libD3D8;
00179     static LPDIRECT3D8      s_D3D;
00180     static D3DCAPS8 *       s_DevCaps;
00181     static deDriverCaps*    s_Caps;
00182     static long             s_NumDevices;
00183 
00184     //private variables
00185     IDirect3DDevice8 *          m_D3DDevice;
00186     long                        m_AdapterNum;
00187     
00188     // cached entries to avoid state changes
00189     deBoolean                   m_DeviceLost;
00190     deBoolean                   m_RenderStatesValid;
00191     deTList <VertexShaderEntry> m_ShaderList;
00192     unsigned long               m_LastShader;
00193     deBoolean                   m_TextureRendered;
00194     deBoolean                   m_LightsEnabled[deD3D8_MAX_LIGHTS];
00195     IdeRenderTexture*           m_CachedTexture;
00196     long                        m_FrameNum;
00197 
00198     // cached data
00199     D3DMATRIX m_WorldMatrix;
00200     D3DMATRIX m_CameraMatrix;
00201     
00202     // some optimizations and leak relief
00203     IdeRenderMaterial::MatSource_t  m_AmbientSource, m_EmissiveSource;
00204     IdeRenderMaterial::MatSource_t  m_DiffuseSource, m_SpecularSource;
00205     deTHashInt <IdeBitmap*>         m_TexturesList;
00206     deTHashInt <IdeVertexBuffer*>   m_VBufferList;
00207     LPDIRECT3DSURFACE8              m_pZBuffer;
00208     IdeBitmap*                      m_pCurrentTarget;
00209     
00210     //private functions
00211     void ReportErrorHR(HRESULT hr);
00212     deBoolean TestDeviceStatus(deBoolean * DeviceCanReset);
00213     deBoolean ResetDevice(D3DPRESENT_PARAMETERS *D3DParams);
00214     deBoolean ReleaseVideoMemResources();
00215     deBoolean BuildD3DParams(deDisplay * Display, D3DPRESENT_PARAMETERS *D3DParams);
00216 
00217     deBoolean SetTextureState(IdeRenderTexture *State);
00218     deBoolean SetLightState(IdeRenderLight *State);
00219     deBoolean SetMaterialState(IdeRenderMaterial *State);
00220 
00221     deBoolean FillBufferInfo(VertexBufferEntry *BufferEntry, IdeVertexBuffer *Vertex, IdeVertexBuffer::BufferType BufferType, deBoolean WipeBuffer);
00222     deBoolean ProcessVertexBuffer(IdeVertexBuffer *Vertex, VertexBufferEntry *VertexBufferInfo, long BufferFlags);
00223 
00224     deBoolean CreateDefaultCachedTexture();
00225 
00226     // manages shader pool and creates/finds one for the specified flags
00227     VertexShaderEntry * GetFixedFunctionShader(IdeVertexBuffer *Vertex);
00228     VertexShaderEntry * LookUpFFShader(long BufferFlags) const;
00229     VertexShaderEntry * MakeFFShader(long BufferFlags);
00230     long DeleteShaders();
00231     //convert to/from D3D BPP
00232     D3DFORMAT ToD3DBPP(IdeDriver::BPP BPPType) const;
00233     IdeDriver::BPP FromD3DBPP(D3DFORMAT BPPType) const;
00234     D3DFORMAT ToD3DZPP(IdeDriver::ZPP ZPPType) const;
00235     IdeDriver::ZPP FromD3DZPP(D3DFORMAT ZPPType) const;
00236     D3DMATERIALCOLORSOURCE ToD3DMatSource(IdeRenderMaterial::MatSource_t source) const;
00237 };
00238 
00239 char* __cdecl HR2String(HRESULT hr, char* szHR);
00240 
00241 extern "C"
00242 {
00243     //include the all important APIs so that we can be used
00244 #ifdef _DEBUG
00245     __declspec(dllexport) deBoolean IsDestiny3DDriverDebug();
00246 #else
00247     __declspec(dllexport) deBoolean IsDestiny3DDriver();
00248 #endif
00249     __declspec(dllexport) IdeDriver *GetDriverInstance(long ID);
00250     __declspec(dllexport) const deDriverInfo *GetDriverInfo(long StructSize);
00251 };
00252 
00253 #endif

Generated on Mon Sep 12 19:58:20 2005 for Destiny3D by doxygen1.3-rc3